package com.ljf.auth;

import com.ljf.framework.LjfManager;
import com.ljf.framework.exception.LjfException;
import com.ljf.framework.filter.*;
import com.ljf.framework.log.LjfLogManager;
import com.ljf.framework.log.LjfLogService;
import com.ljf.framework.router.LjfRouterConstants;
import com.ljf.framework.router.LjfRouterManager;
import com.ljf.framework.security.token.LjfTokenManager;

import java.util.Arrays;
import java.util.List;

/**
 * 说明：
 *
 * @Auther: lijinfeng
 * @Date: 2024/4/26
 */
public class AuthFilter extends LjfAbstractFilter implements LjfFilter {

    LjfLogService log = LjfLogManager.getLogger(AuthFilter.class);

    @Override
    public Integer getOrder() {
        return 10;
    }

    @Override
    public List getIncludeList() {
        return Arrays.asList("/**");
    }

    @Override
    public List getExcludeList() {
        return Arrays.asList(LjfRouterConstants.LOGIN_ROUTER, "logout", "/weixin/login","/auth/kaptchaImage","/sso/auth");
    }

    @Override
    public LjfFilterAuthStrategy getAuthStrategy() {
        return r -> {
            log.info("AuthFilter " + LjfManager.getLjfContext().getRequest().getRequestPath());
            //获得token
            String token = LjfTokenManager.getTokenValue();
            //校验token
            LjfTokenManager.checkToken(token);
            return true;
        };
    }

    @Override
    public boolean doCusFilter() throws Exception {
        LjfFilterManager.addLjfFilter(this);
        return true;
    }



//
//    @Override
//    public boolean doCusFilter(){
//        /*
//         1. 拦截所有请求
//         1.1. 其他请求 对token进行验证
//        */
//        //TODO 将不过滤的请求路径，设置成配置注入
//        List<String> baseExclude = Arrays.asList(LjfRouterConstants.LOGIN_ROUTER,"logout","/weixin/login");
//        List<String> allInclude = Arrays.asList("/**");
//
//        LjfRouterManager.createRouter().match(allInclude).notMatch(baseExclude).check(r -> {
//            log.info("AuthFilter " + LjfManager.getLjfContext().getRequest().getRequestPath());
//            //获得token
//            String token = LjfTokenManager.getTokenValue();
//            //校验token
//            LjfTokenManager.checkToken(token);
//
//        });
//        return true;
//    }

}
